package com.itheima.tilas.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tilas.Utils.ResultUtil;
import com.itheima.tilas.entity.Log;
import com.itheima.tilas.mapper.LogMapper;
import com.itheima.tilas.po.SelectLogPageParam;
import com.itheima.tilas.service.LogService;
import io.jsonwebtoken.Jwt;
import io.jsonwebtoken.JwtBuilder;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 日志实现类
 * @author 132
 */
@Service
public class LogServiceImpl implements LogService {
    @Resource
    LogMapper loggerMapper;
    @Override
    public ResultUtil selectLogPage(SelectLogPageParam param) {
        Page<Object> page = PageHelper.startPage(param.getPage(), param.getPageSize());
        List<Log> logs = loggerMapper.selectLogPage(param);
        if (CollectionUtils.isEmpty(logs)){
            return ResultUtil.fail("本次查询失败");
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("total",page.getTotal());
        jsonObject.put("rows",logs);
        return ResultUtil.success("本次查询成功",jsonObject);
    }
}
